<template>
	<view class="ts-ad-wraper" v-if="!bannerHidden">
		<view class="ts-ad">
			<view class="ts-ad-content" @tap="handleTap">
				<slot></slot>
			</view>
			<view class="ts-ad-close-button" @tap="handleClose">
				<image :src="closeButtonImage" mode="widthFix"></image>
			</view>
		</view>
	</view>

</template>

<script>
	export default {
		name: 'ts-ad',
		data() {
			return {
				bannerHidden: false,
			}
		},
		model: {
			prop: 'hidden',
			event: 'close'
		},
		props: {
			hidden: {
				type: [Boolean, String],
				default: false
			},
			closeButtonImage: {
				type: String,
				default: ''
			}
		},
		watch: {
			bannerHidden(val) {
				this.$emit('close', val);
			},
			hidden(val) {
				console.log(val)
				this.updateValue(val);
			}
		},
		mounted() {
			this.updateValue(this.hidden);
		},
		methods: {
			updateValue(val) {
				this.bannerHidden = !!val;
			},
			handleClose() {
				this.bannerHidden = true;
			},
			handleTap() {
				console.log('Tap')
				this.$emit('tap');
			}
		}
	}
</script>

<style>
	.ts-ad-wraper {
		display: flex;
		flex-direction: column;
		flex: 1;
	}

	.ts-ad {
		background: #DEF0F0;
		display: block;
		position: relative;
		width: 100%;
	}

	.ts-ad-content {
		display: block;
		width: 100%;
	}

	.ts-ad-close-button {
		display: block;
		position: absolute;
		right: 0;
		top: 0;
	}

	.ts-ad-close-button image {
		width: 60px;
	}
</style>
